<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PublicController;
use App\Http\Controllers\admin\UserController;
use App\Http\Controllers\admin\ArticleController;
use App\Http\Controllers\CommentController;
use App\Models\Article;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    $article = new Article();
    $articles = $article -> get();
    $user = auth('admin')->user();
    return view('index',compact('articles','user'));
});

Route::get('/test',function() {

	$data = [
        		'uname' => $faker -> name(),
        		'email' => $faker -> email(),
        		'phone' => $faker -> phoneNumber(),
        		'password' => bcrypt('liang..'),
        		'active' => mt_rand(0,1)
        	];

      dump($data);
});

/*
	公共路由 public 登录和注册
 */
Route::any('/public/login',[PublicController::class,'login'])->name('login');
Route::any('/public/register',[PublicController::class,'register']);
Route::get('/public/logout',[PublicController::class,'logout']);

Route::middleware('auth') -> group(function() {
    /**
     * 后台路由  用户管理
     */
    Route::get('/admin/user/index',[UserController::class,'index']);
    Route::get('/admin/user/profile/{id}',[UserController::class,'profile']);
    Route::get('/admin/user/del/{id}',[UserController::class,'del']);
    Route::post('/admin/user/edit/{id}',[UserController::class,'edit']);


    /**
     * 后台路由  文章管理
     */
    Route::get('/admin/article/index', [ArticleController::class, 'index']);
    Route::any('/admin/article/add', [ArticleController::class, 'add']);
    Route::any('/admin/article/edit/{id}', [ArticleController::class, 'edit']);
    Route::get('/admin/article/del/{id}', [ArticleController::class, 'del']);
});

// 不需要中间件验证
Route::get('/admin/article/display/{id}', [ArticleController::class, 'display']);

Route::post('/comment/add',[CommentController::class,'add']);
